use lazy_static::lazy_static;
use crate::core::block::Block;
use async_std::sync::{Arc, Mutex};

lazy_static! {
    pub static ref CHAIN :Arc<Mutex<ChainWrap>> =Arc::new(Mutex::new(ChainWrap::new()));
}

/// 区块链包装体
pub struct ChainWrap {
    chain: Vec<Block>,
}

impl Default for ChainWrap {
    fn default() -> Self {
        Self::new()
    }
}

impl ChainWrap {
    /// 创建新的区块链
    pub fn new() -> Self {
        ChainWrap {
            chain: vec![Block::god()],
        }
    }
}

impl ChainWrap {
    pub fn chain(&self) -> &Vec<Block> {
        &self.chain
    }

    pub fn chain_mut(&mut self) -> &mut Vec<Block> {
        &mut self.chain
    }
}